""" AdminUser Model """

from masoniteorm.models import Model
from masoniteorm.collection import Collection
from masonite.facades import Config


class AdminUser(Model):
    """AdminUser Model"""

    FIELDS = {
        'is_lock': {0: '否', 1: '是'}
    }

    @classmethod
    def generate_log(cls, account, password, salt, nickname='', admin_role_id=0, is_lock=0, is_deleted=0):
        """
        生成记录
        @param string account: 账户
        @param string password: 密码
        @param string nickname: 昵称
        @param string salt: 加密盐
        @param int    admin_role_id: 角色 ID
        @param int    is_lock:
        @param int    is_deleted:
        @return: None
        """
        insert = {
            'account': account,
            'password': password,
            'nickname': nickname,
            'salt': salt,
            'admin_role_id': admin_role_id,
            'is_lock': is_lock,
            'is_deleted': is_deleted
        }
        cls.create(insert)

    @classmethod
    def is_super_admin(cls, account):
        return account in Config.get('super_admin.account')

    @classmethod
    def get_account(cls):
        """
        获取所有账户
        @return: {1: 'myadmin', 2: 'zhang_san'}
        """
        return Collection(cls.get()).pluck('account', 'id').all()
